package com.yootk.main;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.WritableResource;

import java.io.File;
import java.io.OutputStream;

/**
 * WritableResource，资源写入
 */
public class Demo03_WritableResource {
    public static void main(String[] args) throws Exception {
        test1();
    }

    /**
     * 实现文件内容的输出
     */
    public static void test1() throws Exception {
        String path = "F:" + File.separator + "muyan" + File.separator + "message.txt";
        File file = new File(path);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        WritableResource resource = new FileSystemResource(file);
        OutputStream output = resource.getOutputStream();
        for (int x = 0; x < 10; x++) {
            output.write("沐言科技：www.yootk.com\r\n".getBytes());  // 数据的写入
        }
        output.close();
    }
}
